#pragma once
#include <Windows.h>
#include <list>
#include <map>
using namespace std;
using std::multimap;
using std::pair;
using std::list;

#include "Event.h"
#include "IListener.h"
#include <vector>

class CEventSystem
{
private:
	multimap<int, IListener*>	m_mListeners;
	list<CEvent>				m_vCurEvents;
	vector<IListener*>			m_vToBeRemoved;
	bool						m_bProcessing;
	
	void DispatchEvent(CEvent* pEvent);
	bool CheckIfRegistered(int nEventID, IListener* pListener);

	CEventSystem(){}
	~CEventSystem(){}
public:
	static CEventSystem* GetInstance();
	void AddListener( int nEventID, IListener* pListener);
	void SendEvent( int nEventID, void* pVoid = NULL );
	void UnregisterListener( int nEventID, IListener* pListener);
	void RemoveListener( IListener* pListener);
	void ProcessEvents();
	void Clear();
	void Shutdown();
};